<template>
    <TabGrayEasyCard :title="'出租分析'" @onMore="goDetail(props.permi)" :tabs="card.tabs" :curTab="card.curTab"
        :tabRight="card.tabRight" @onChange="changeTab" :grayCardList="card.grayCardList" :lineText="''" :barText="''"
        :unitText="`单位：${card.unitText}`" :updateText="card.updateText"
        v-btnPermi="{ permi: props.permi, noReport: true, isHiden: true }">

        <slot>
            <el-table :data="card.tableData" height="100%">
                <el-table-column prop="buildFloorName" :label="tableLabel" :align="'left'" />
                <el-table-column label="租赁面积" :align="'right'">
                    <template #default="scope">
                        {{ toThousands(scope.row.netRentArea) }}
                    </template>
                </el-table-column>
                <el-table-column label="意向率" :align="'right'">
                    <template #default="scope">
                        {{ scope.row.intentionAreaRate == '-' ? scope.row.intentionAreaRate : scope.row.intentionAreaRate +
                            '%' }}
                    </template>
                </el-table-column>
                <el-table-column label="出租率" :align="'right'">
                    <template #default="scope">
                        {{ scope.row.signRate == '-' ? scope.row.signRate : scope.row.signRate + '%' }}
                    </template>
                </el-table-column>
                <el-table-column label="空置面积" :align="'right'">
                    <template #default="scope">
                        {{ toThousands(scope.row.kongzhiArea) }}
                    </template>
                </el-table-column>
            </el-table>
        </slot>
    </TabGrayEasyCard>
</template>

<script setup>
import TabGrayEasyCard from '@/DbComponents/tabGrayEasyCard'
import { toThousands } from '@/utils/number-util'
import dashBoardApi from '@/api/Prepare/Business/dashBoard'
import BusinessDashBoardApi from '@/api/Manage/Business/dashBoard'
import { ref, reactive, watch, computed } from 'vue'
import { reportLog } from '@/utils/reportLog'

const props = defineProps({
    permi: {
        type: String,
        required: false,
        default: ''
    },
    hideList: {
        type: Array,
        required: false,
    },
    biProjectCode: {
        type: String,
        required: false,
        default: ''
    },
    updateDate: {
        type: String,
        required: false,
        default: ''
    }
})
const card = reactive(
    {
        tabs: [{ label: '全部', value: '全部' }],
        curTab: '全部',
        tabRight: '',
        grayCardList: [{ label: '意向率', value: '', unit: '%', color: '', des: '' }, { label: '出租率', value: '', unit: '%', color: '', des: '' }, { label: '空置面积', value: '', unit: '', color: '', des: '' }],
        unitText: '㎡',
        updateText: '',
        tableData: [],
        // startDate: '',
        // endDate: '',
    }
)
const getCardData = () => {
    dashBoardApi.prepareRentCardApi({ biProjectCode: props.biProjectCode, timeType: card.curTab, dataTime: props.updateDate }).then((res) => {
        if (res.data.code == 200) {
            card.tabRight = res.data.data.timeLab
            card.grayCardList[0].value = toThousands(res.data.data.intendedRate)
            card.grayCardList[0].color = res.data.data.intendedRateColorLab
            card.grayCardList[1].value = toThousands(res.data.data.signRate)
            card.grayCardList[1].color = res.data.data.signRateColorLab
            card.grayCardList[2].value = toThousands(res.data.data.kongzhiArea)
            card.unitText = res.data.data.valueUnit
        }
    }).catch(err => {
        console.log(err)
    });
}
const getChartData = () => {
    dashBoardApi.prepareRentCardListApi({ biProjectCode: props.biProjectCode, timeType: card.curTab, dataTime: props.updateDate }).then((res) => {
        if (res.data.code == 200) {
            card.tableData = res.data.data
        }
    }).catch(err => {
        console.log(err)
    });
}

const goDetail = (permi) => {
    reportLog({
        type: 4,
        resourceKey: permi,
    })
}
const changeTab = (value) => {
    console.log(value)
}

let tableLabel = ref('楼层')
const getBuilding = () => {
    BusinessDashBoardApi.isBuildingsApi({ biProjectCode: props.biProjectCode }).then((res) => {
        if (res.code == 200) {
            tableLabel.value = res.data ? '楼栋' : '楼层'
        }
    }).catch(err => {
        console.log(err)
    });
}
getBuilding()
getCardData()
getChartData()

const biProjectCode = computed(() => {
    return props.biProjectCode
});
watch(biProjectCode, () => {
    getBuilding()
    getCardData()
    getChartData()
}, { deep: true });
</script>

<style scoped lang="scss"></style>
